package com.ruoyi.wechat.service.impl;

import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.IdUtils;
import com.ruoyi.wechat.mapper.DynamicImgMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.wechat.mapper.DynamicMapper;
import com.ruoyi.wechat.domain.Dynamic;
import com.ruoyi.wechat.service.IDynamicService;

/**
 * dynamicService业务层处理
 * 
 * @author yeluochen
 * @date 2024-12-24
 */
@Service
public class DynamicServiceImpl implements IDynamicService 
{
    @Autowired
    private DynamicMapper dynamicMapper;

    @Autowired
    private DynamicImgMapper dynamicImgMapper;

    /**
     * 查询dynamic
     * 
     * @param id dynamic主键
     * @return dynamic
     */
    @Override
    public Dynamic selectDynamicById(Long id)
    {
        return dynamicMapper.selectDynamicById(id);
    }

    /**
     * 查询dynamic列表
     * 
     * @param dynamic dynamic
     * @return dynamic
     */
    @Override
    public List<Dynamic> selectDynamicList(Dynamic dynamic)
    {
        return dynamicMapper.selectDynamicList(dynamic);
    }
    @Override
    public List<Dynamic> selectDynamicAndImageList(Dynamic dynamic)
    {

        return dynamicMapper.selectDynamicAndImageList(dynamic);
    }

    /**
     * 新增dynamic
     * 
     * @param dynamic dynamic
     * @return 结果
     */
    @Override
    public int insertDynamic(Dynamic dynamic)
    {
        String id = IdUtils.randomUUID();
        for(int i = 0; i < dynamic.getImages().size(); i++){
            dynamic.getImages().get(i).setDynamicId(id);
            dynamic.getImages().get(i).setId(IdUtils.randomUUID());
            dynamicImgMapper.insertDynamicImg(dynamic.getImages().get(i));
        }
//        dynamic.setCreateTime(sysdate());
        dynamic.setId(id);
        dynamic.setCreateTime(DateUtils.getNowDate());
        dynamicMapper.insertDynamic(dynamic);
        return 1;
    }

    /**
     * 修改dynamic
     * 
     * @param dynamic dynamic
     * @return 结果
     */
    @Override
    public int updateDynamic(Dynamic dynamic)
    {
        return dynamicMapper.updateDynamic(dynamic);
    }

    /**
     * 批量删除dynamic
     * 
     * @param ids 需要删除的dynamic主键
     * @return 结果
     */
    @Override
    public int deleteDynamicByIds(Long[] ids)
    {
        return dynamicMapper.deleteDynamicByIds(ids);
    }

    /**
     * 删除dynamic信息
     * 
     * @param id dynamic主键
     * @return 结果
     */
    @Override
    public int deleteDynamicById(Long id)
    {
        return dynamicMapper.deleteDynamicById(id);
    }
}
